package com.tdkj.action.backstage.decorate;

import javax.annotation.Resource;
import org.hibernate.Query;
import com.tdkj.action.BaseAction;
import com.tdkj.model.decorate.BeanStyle;
import com.tdkj.model.decorate.BeanStyleCustom;
import com.tdkj.service.decorate.IBeanStyleCustomService;

public class StyleCustomAction extends BaseAction {
    
	private IBeanStyleCustomService styleCustomService;
	
	private BeanStyleCustom custom ;
	
	private Long styleId;
	
	public String execute() {
		
		String hql = "select bean from " + BeanStyleCustom.class.getName() + " as bean where bean.style.id='"+styleId+"' order by bean.id";
		Query query = this.createQuery(hql);
		this.queryByPage(query, "styleCustomAction.action", 10);
		
		return "success";
	}
	
	public String add() {
		styleCustomService.save(custom);
		return execute();
	}
	
	public String update() {
		styleCustomService.saveOrUpdate(custom, BeanStyleCustom.class);
		return execute();
	}

	public String delete() {
		styleCustomService.delete(custom.getId(), BeanStyleCustom.class);
		return execute();
	}
	
	public String edit() {
		custom = styleCustomService.findById(custom.getId(), BeanStyleCustom.class);
		return "edit";
	}

	public BeanStyleCustom getCustom() {
		return custom;
	}

	public void setCustom(BeanStyleCustom custom) {
		this.custom = custom;
	}

	public Long getStyleId() {
		return styleId;
	}

	public void setStyleId(Long styleId) {
		this.styleId = styleId;
	}

	@Resource
	public void setStyleCustomService(IBeanStyleCustomService styleCustomService) {
		this.styleCustomService = styleCustomService;
	}


	
}
